package com.itany.nmms.util;

import com.itany.nmms.exception.MD5ErrorException;
import sun.misc.BASE64Encoder;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Author: shixiaojun@itany.com
 * Date: 2020/8/14 14:42
 * Version: 1.0SNAPSHOT
 **/
public class MD5Util {

    public static String md5(String s){
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] b = md.digest(s.getBytes());
            BASE64Encoder encoder = new BASE64Encoder();
            return encoder.encode(b);
        } catch (NoSuchAlgorithmException e) {
            throw new MD5ErrorException("加密方式有误");
        }
    }

    public static void main(String[] args) {
        System.out.println(md5("admin"));
    }

}
